<template>
    <div class="app-container">
        <div style="text-align: center;margin-bottom: 30px">发布预警信息</div>
        <el-row :gutter="10">
            <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                <el-form :model="infoForm" ref="infoForm" label-width="150px">
                    <el-form-item label="巡查人员" prop="enterpriseId" >
                        <el-select v-model="infoForm.userId" placeholder="请选择巡查人员" style="width: 100%">
                            <el-option v-for="(item,index) in UserList" :key="index"  :value="item.ucId" :label="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                    <div align="center">
                        <el-button type="danger" @click="cancelInfo" >取消</el-button>
                        <el-button type="primary" @click="publish" >发布</el-button>
                    </div>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import {getInUserList} from "@/api/enterprise";
import {getInFireAlarmInfoVo, updateInFireAlarmInfo} from "@/api/fireAlarmInfo";
export default {
    name: "publish",
    data() {
        return {
            infoForm: {
                ucId:this.$route.query.ucId
            },
            UserList:[],
        }
    },
    created() {
        this.getInUserList()
    },
    methods:{
        getInUserList(){
            getInUserList({deleted:false,flagId:this.$route.query.eId,type:1}).then(res=>{
                this.UserList = res.data
            }).catch(error=>{

            })
        },
        cancelInfo() {
            let view = {
                fullPath: this.$route.path,
                path: this.$route.path,
                name: this.$route.name,
                meta: {...this.$route.meta}
            }
            this.$store.dispatch('tagsView/delView', view).then(({visitedViews}) => {
                if (view.path == this.$route.path) {
                    const latestView = visitedViews.slice(-1)[0]
                    console.log(latestView)
                    if (latestView) {
                        this.$router.push(latestView.fullPath)
                    } else {
                        // now the default is to redirect to the home page if there is no tags-view,
                        // you can adjust it according to your needs.
                        if (view.name === 'Dashboard') {
                            // to reload home page
                            this.$router.replace({path: '/redirect' + view.fullPath})
                        } else {
                            this.$router.push('/')
                        }
                    }
                }
            })
        },
        publish(){
            this.$refs['infoForm'].validate(valid => {
                if (valid) {
                    updateInFireAlarmInfo(this.infoForm).then(res => {
                        this.$notify.success({
                            title: '成功',
                            message: "指定巡检员成功"
                        })
                        this.cancelInfo()
                    }).catch(res => {

                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {

                    console.log("表单验证不通过")
                }
            })
        }
    }
}
</script>

<style scoped>

</style>